package com.nanhang.controller;

import com.nanhang.entity.Specification;
import com.nanhang.entity.SpecificationOption;
import com.nanhang.util.PageResult;
import com.nanhang.util.R;
import com.nanhang.vo.SpecificationOptionVO;
import com.nanhang.vo.SpecificationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nanhang.service.SpecificationService;

import java.util.List;

@RestController
@RequestMapping("/specification")
public class SpecificationController {
    @Autowired
    private SpecificationService specificationService;

    @GetMapping("/list")
    public List<Specification> findSpecification() {
        return specificationService.findSpecification();
    }
    @GetMapping("/findByPage")
    public PageResult<Specification> findByPage(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize){
        return specificationService.findByPage(page,pageSize);
    }

    @PostMapping("/search")
    public PageResult<Specification> search(@RequestParam("page") Integer page,
                                                  @RequestParam("pageSize") Integer pageSize,
                                                  @RequestBody(required = false) SpecificationVO specificationVO){
        return specificationService.search(page,pageSize,specificationVO);
    }

    @PostMapping("/save")
    public R save(@RequestBody Specification specification){
        return specificationService.save(specification) ? R.ok().message("添加成功！") : R.error().message("添加失败！");
    }



}
